<?php
// $Id$

/**
 * Controller_Admin_Link 控制器
 */
class Controller_Admin_Link extends Controller_Abstract
{

	function actionIndex()
	{
        $links = Link::find()->order('position, sort')->getAll();
        $this->_view['links'] = $links;
	}

    function actionEdit(){
        $l = Link::findById($this->_context->lid)->getOne();

        if($this->_context->isPost()){

            $l->changeProps($_POST);

            try{
                $l->save();

                return $this->_redirect(url('.', 'lid/'.$l->id()));

            }catch(QDB_ActiveRecord_ValidateFailedException  $e){
                $this->_view['errorMsg'] = '错误：'.$e->getMessage();
            }
        }

        $this->_view['l'] = $l;
        $this->_view['title'] = $l->id()?'编辑链接':'添加链接';
    }

    function actionDel(){
        $l = Link::findById($this->_context->lid)->getOne();
        if($l->id())$l->destroy();

        return $this->_redirect(url('/'));
    }
}


